package com.powernode.lambda.lambda;

import com.powernode.lambda.Student;

import java.util.stream.Stream;

/**
 * 方法引用之this和super
 */
public class Lambda07 {
    public static void main(String[] args) {
        Stream<Student> studentStream1 = Stream.of(
                new Student("张无忌", 26, "男"),
                new Student("赵敏", 22, "女"),
                new Student("周芷若", 21, "女")
        );
        Stream<Student> studentStream2 = Stream.of(
                new Student("张无忌", 26, "男"),
                new Student("赵敏", 22, "女"),
                new Student("周芷若", 21, "女")
        );
        Util util = new Util();
        util.ifSex(studentStream1);
        System.out.println("==========");
        Util utilExt = new UtilExt();
        utilExt.ifSex(studentStream2);
    }

    static class Util{
        public boolean isMale(Student student){
            return "男".equals(student.getSex());
        }

        public boolean isFeMale(Student student){
            return "女".equals(student.getSex());
        }

        void ifSex(Stream<Student> stream){
            stream.filter(this::isMale)//找本类的isFeMale方法
                    .forEach(System.out::println);
        }
    }

    static class UtilExt extends Util{

        void ifSex(Stream<Student> stream){
            stream.filter(super::isFeMale)//找父类的isFeMale方法
                    .forEach(System.out::println);
        }
    }
}
